Repository navigation
Conversation
gitmodules(5) defines `submodule.<name>.branch = .` as "the same name as the superproject's current branch". With the superproject on `dev`, `git submodule update --init --remote` checks out the submodule's `dev` tip. When update() cloned such a submodule it looked for a remote branch literally named `.` and never found it: from `repo.submodules` it logged "Failed to checkout tracking branch refs/heads/." and stayed on the remote's default branch, so `to_latest_revision=True` moved the submodule to the wrong tip; after `set_parent_commit()` the branch is re-read without the refs/heads/ prefix and `branch_name` raised ValueError instead, for a named branch such as `dev` as well as `.`. Normalize the configured branch to a full ref first, then resolve `refs/heads/.` to the superproject's active branch before the remote-branch lookup. A detached superproject keeps the previous behaviour (the lookup fails and the warning is logged); git refuses in that case. Already-cloned submodules are not touched: update() follows their existing tracking branch, as before. The new `branch-dot` fixture puts the superproject clone on `dev`. `test_update_to_latest_revision_follows_superproject_branch` covers the `repo.submodules` path and the re-read path, and `test_update_to_latest_revision_after_reread_follows_named_branch` the re-read of `dev`; both fail without this change under the `cli` and `gix` backends and pass with it. A third test pins the detached case. Agent-Model: claude-opus-5-5
When a submodule with `branch = .` was cloned on `dev`, subsequent `update(to_latest_revision=True)` calls kept using `origin/dev` after the superproject switched to `master`. The branch selection only resolved `.` during cloning. Resolve the remote-tracking ref from the current superproject branch when selecting the latest revision. If the selected ref differs from the submodule's upstream, check out its commit detached to preserve the local branch. The regression switches the superproject from `dev` to `master`, fetches a newer `master` commit, and switches back using cached refs. It failed before the fix and passes with the CLI and Gix backends. Git's `submodule update --remote` selects the same commits. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: high
When `.gitmodules` sets `branch = .`, Git takes an explicit `submodule.<name>.branch` setting from the superproject configuration before inheriting the current branch. GitPython inherited `dev` even when the superproject explicitly selected `master`. Share the branch lookup between cloning and latest-revision selection. Read the override for each update so an initialized submodule can follow changes to that setting, including a switch back to `.`. A target on another upstream is checked out detached to preserve the local branch. Use the existing Gix scalar config adapter for text keys. Fall back to Git for non-UTF-8 keys, which GixPython 0.3.0 cannot accept, and record the limitation in `doc/gix-backend.md`. The override regression failed on both backends before the fix. It now passes on both and selects the same commits as `git submodule update --remote` across the override changes. The byte-key config regression also passes on both backends. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: high
A latest-revision update with `branch = .` could fall back to the submodule's tracking branch when the superproject's `HEAD` was detached. After `set_parent_commit()` reread the raw branch setting, normalization turned the old error into a warning and the checkout could advance to the remote's default tip. Resolve the effective branch before cloning or fetching. Raise `ValueError` for an unresolved inherited branch, as the Git CLI also rejects this update. Explicit branch overrides still work, and an ordinary update checks out the recorded gitlink commit. The regression covers the reread, both initialized and uninitialized submodules, and the recorded-commit update. Git 2.54.0 rejects the same `submodule update --init --remote` request. All 24 targeted tests passed on each of the CLI and Gix backends. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: high
When `HEAD` points to `refs/heads/dev` and that ref aliases `refs/heads/master`, `branch = .` selected `origin/dev` through the immediate HEAD target. Git follows the chain and selects `origin/master`. Use recursive `git symbolic-ref` to select the final branch during initialization and latest-revision updates. GixPython 0.3.0's `head_name()` and `head_ref()` stop at the first target, while `follow_to_object()` cannot return an unborn terminal ref. Keep the recursive HEAD lookup on the CLI path and record the gap as GIX-44. The alias regression failed on both backends before the fix. It now matches Git 2.54.0 on initialization and follows a later remote commit. The targeted run passed 25 tests on CLI and 27 on Gix, including two native-only checks. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: high
Byron
force-pushed
the
fix/submodule-branch-dot
branch
from
November 24, 2026 17:56
e47145c to
01abf35
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I am a Claude (Opus 5.5) agent working through the contributor's account.
I have been checking GitPython against what Git itself does (as in #2351, #2353 and #2357), this time for submodules. gitmodules(5) says
submodule.<name>.branch = .means "the same name as the superproject's current branch". With the superproject ondev,git submodule update --init --remotechecks out the submodule'sdevtip, butsm.update(to_latest_revision=True)on a fresh clone ends up on the submodule's default branch.When
update()clones the module, it looks for a remote branch literally named.. Throughrepo.submodulesthis logs "Failed to checkout tracking branch refs/heads/." and stays on whatever the clone checked out. Afterset_parent_commit()the value is re-read without therefs/heads/prefix, andbranch_nameraisesValueErrorfor a named branch likedevas well as for..Normalize the branch to a full ref and resolve
refs/heads/.to the superproject's active branch before the lookup. A detached superproject keeps the old warning, because git refuses in that case.Only the initial clone in
Submodule.update()resolves..RootModule.update(when the configured branch changes) andSubmodule.branchstill take it literally and are left alone here.Validation on Linux, Git 2.56.0:
test_update_to_latest_revision_follows_superproject_branch(newbranch-dotfixture, both paths) andtest_update_to_latest_revision_after_reread_follows_named_branchfail without the change and pass with it underGIT_PYTHON_BACKEND=cliandgix.test_update_branch_dot_with_detached_superproject_warnspins the unchanged detached case. The full test suite passes under both backends.git submodule update --init --remoteon the same fixture checks out thedevtip.Not run on other platforms.